using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class UIMgr : MonoBehaviour
{
    public static UIMgr Instance;
    public List<BaseUI> baseUI;
    private Dictionary<Type, BaseUI> uiDict;

    private void Awake()
    {
        Instance = this;
        Init();
    }

    private void Init()
    {
        uiDict = baseUI.ToDictionary(item => item.GetType(), item => item);
    }

    private void OnDestroy()
    {
        Instance = null;
    }

    public void OpenUI<T>(params object[] args) where T : BaseUI
    {
        if (uiDict.TryGetValue(typeof(T), out var ui))
        {
            ui.Open(args);
        }
        else
        {
            Debug.LogError("û�������8ҳ��");
        }
    }

    public void CloseUI<T>() where T : BaseUI
    {
        if (uiDict.TryGetValue(typeof(T), out var ui))
        {
            ui.Close();
        }
        else
        {
            Debug.LogError("û�������8ҳ��");
        }
    }
}
